package com.lonely.purchase.enums;

import com.lonely.common.enums.StatusEnumInterface;
import com.lonely.common.exception.BusinessException;
import lombok.Getter;

/**
 * @author: 黄志标
 * @date: 2025/6/24 9:32
 * @description: 物料采购相关枚举
 */
public class MaterialPurchaseEnum {


    /**
     * 采购类型枚举
     */
    @Getter
    public enum PurchaseTypeEnum {

        /**
         * shein同步订单
         */
        SHEIN(1),

        /**
         * 本地订单
         */
        LOCAL(2);

        /**
         * 采购类型
         */
        private final int type;

        PurchaseTypeEnum(int type) {
            this.type = type;
        }

        /**
         * 根据采购类型获取对应枚举
         *
         * @param type
         * @return
         */
        public static PurchaseTypeEnum getByType(int type) {
            for (PurchaseTypeEnum value : values()) {
                if (value.getType() == type) {
                    return value;
                }
            }
            throw new BusinessException("采购类型不存在");
        }

    }


    /**
     * 物料采购状态枚举
     */
    @Getter
    public enum MaterialPurchaseStatusEnum implements StatusEnumInterface {
        /**
         * 待采购
         */
        TO_BE_PURCHASED(1,"待采购"),

        /**
         * 待回料
         */
        TO_BE_RECYCLED_MATERIALS(2,"待回料"),

        /**
         * 已完成
         */
        COMPLETED(3,"已完成");

        /**
         * 状态
         */
        private final int status;

        /**
         * 状态名称
         */
        private final String statusName;

        MaterialPurchaseStatusEnum(int status, String statusName) {
            this.status = status;
            this.statusName = statusName;
        }
    }


    /**
     * 物料采购异常类型枚举
     */
    @Getter
    public enum MaterialPurchaseFailTypeEnum {
        /**
         * 扣减
         */
        deduction(1),

        /**
         * 补料
         */
        replenish(2);

        /**
         * 异常状态
         */
        private final int failType;

        MaterialPurchaseFailTypeEnum(int failType) {
            this.failType = failType;
        }

        /**
         * 根据采购异常类型获取对应枚举
         *
         * @param failType
         * @return
         */
        public static MaterialPurchaseFailTypeEnum getByFailType(int failType) {
            for (MaterialPurchaseFailTypeEnum value : values()) {
                if (value.getFailType() == failType) {
                    return value;
                }
            }
            throw new BusinessException("采购异常类型不存在");
        }
    }


}
